home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11429 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: REQUEST: Recursive functions
  5. Date: Sun, 24 Mar 96 01:24:55 GMT
  6. Organization: none
  7. Message-ID: <827630695snz@genesis.demon.co.uk>
  8. References: <4h7lft$8ql@cis.clark.edu> <3150334B.1802@willows.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <3150334B.1802@willows.com>
  15.            tarang@willows.com "Tarang Deshpande" writes:
  16.  
  17. >Michael Talmage wrote:
  18. >> 
  19. >> I need some help to write a recursive function that will move a mouse through
  20. >> a maze to find some cheese at the end.  My instructor did not really teach us
  21. >> how to write recursive functions in class.  Any help will be appreciated.
  22. >> 
  23. >
  24. >I'm not going to tell you the answer but here is a quick leson in
  25. >recursion.  First of all anything you do recursively can be done 
  26. >using loops.  But using loops is more complicated and cumbersome whereas
  27. >recursion is more elegant and simple.
  28.  
  29. In the relatively few cases that model well recursively that is true,
  30. otherwise it is not. This is somewhat language dependent but you are
  31. posting to comp.lang.c.
  32.  
  33. > However this does not mean that
  34. >you should always use recusion because recursion make heavy use of the
  35. >stack and this can cause you to run out of memory.
  36.  
  37. Even if the C language guaranteed tail-end recursion elimination you
  38. would still write iterative loops as loops.
  39.  
  40. >What recusion does is to divide the problem into two or more parts.
  41.  
  42. It defines the problem in terms of a simpler form of itself. It must
  43. eventually reach a point where the solution can be determined directly or
  44. some other termination condition for it to be valid (i.e. not continue
  45. on indefinitely).
  46.  
  47. -- 
  48. -----------------------------------------
  49. Lawrence Kirby | fred@genesis.demon.co.uk
  50. Wilts, England | 70734.126@compuserve.com
  51. -----------------------------------------
  52.